<?php

namespace app\model;

//use support\Model;
//use app\controller\IndexController;
use app\controller\wmapi\PublicCommentController;
use support\Db;
use Illuminate\Database\Eloquent\Model;
use app\controller\wmapi\IndexController;

class WaAccountInformationExamineApprove
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'wa_account_information_examine_approve';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;


    /**
     * @param $page
     * @param $pageNum
     * @param $purchasecontractsn
     * @param string[] $fields
     * @param array $condition
     * @param array $between
     * @return false|string
     */
    public static function list($param, $adminId, $page, $pageNum, $whereNotIn, $purchaseOrdersn, $fields = ['*'], $condition = [], $between = [])
    {
        $offset = ($page - 1) * $pageNum;
        // $purchaseOrdersn 为空 就是没有当前登录用户的审核订单
        // 数组转对象  get_object_vars($purchaseOrdersn)
        if (gettype($purchaseOrdersn) == "object") {
            $purchaseOrdersn = get_object_vars($purchaseOrdersn); // 对象转数组函数
        } elseif (gettype($purchaseOrdersn) == "array") {
            $purchaseOrdersn = $purchaseOrdersn;
        }
        $condition [] = ['is_show', '=', 1];

        /**
         * 先获取审批中 待审批的 订单编号 和对应的审批id或编号
         * 审批流中的 部门id 必须是 当前人员的部门
         * 遍历审批流中的 部门admin_ids 中必须有当前人员 有他 但是并没有审批通过的状态就需要展示（因为轮到他时会有一条 0 待审批的状态 其它人会有 通过的状态 或者没有待审批记录）
         *
         */
        $wai_approve_sn = []; // 待当前人员审批的订单
        $where_approve = [];
        $where_approve [] = ['status', '=', 0]; // 先获取审批中 待审批的 订单编号 和对应的审批id或编号
        $approve = WaAccountInformationExamineApprove::all($where_approve);
        $approve = json_decode($approve);
        if ($approve) {
            foreach ($approve as $kap) {
//                $where_approve_flow = [];
//                $where_approve_flow [] = ['ai_no', '=', $kap->ai_no];
//                //先判断 是否有 通过的  撤回  驳回的 不用考虑 因为上一步筛选的就是待审批中的审批订单
//                $where_approve_flow [] = ['status', '=', 1]; // 因为轮到他时会有一条 0 待审批的状态 其它人会有 通过的状态 或者没有待审批记录
//                $approve_flow = WaAccountInformationExamineApproveFlow::all($where_approve_flow);
//                $approve_flow = json_decode($approve_flow);
//                if (!$approve_flow){
                // 因为轮到他时会有一条 0 待审批的状态 其它人会有 通过的状态 或者没有待审批记录  只要排除 有人审核通过 且本人没有审核过 就是本人待审核
                $where_approve_flow_0 = [];
                $where_approve_flow_0 [] = ['ai_no', '=', $kap->ai_no];
                $where_approve_flow_0 [] = ['status', '=', 0]; // 因为轮到他时会有一条 0 待审批的状态 其它人会有 通过的状态 或者没有待审批记录
                $approve_flow_0 = WaAccountInformationExamineApproveFlow::all($where_approve_flow_0);
                $approve_flow_0 = json_decode($approve_flow_0);
                if ($approve_flow_0) {
                    foreach ($approve_flow_0 as $kapf0) {
                        // 筛出来 还要加一层保险 确保 部门中审核人员 由本人
                        if ($kapf0->admin_ids) {
                            $admin_ids = json_decode($kapf0->admin_ids);
                            if (in_array($adminId->id, $admin_ids)) {
                                // 这个时候把审批订单编号扔出来 就是待当前人员待审核的数据
                                array_push($wai_approve_sn, $kap->ai_no);
                            }
                        }
                    }
                }
//                }
            }

        }
        if ($param['status'] == 4) {
            if ($between) {
                $model = Db::table('wa_account_information_examine_approve')
                    ->select($fields)
                    ->where($condition)
                    ->whereIn('ai_no', $wai_approve_sn)
//                    ->whereNotIn('status',$whereNotIn)
                    ->whereBetween('created_at', $between);
            } else {
                $model = Db::table('wa_account_information_examine_approve')
                    ->select($fields)
                    ->where($condition)
//                    ->whereNotIn('status',$whereNotIn)
                    ->whereIn('ai_no', $wai_approve_sn);
            }
        } else {
            if ($between) {
                $model = Db::table('wa_account_information_examine_approve')
                    ->select($fields)
                    ->where($condition)
                    ->whereNotIn('status', $whereNotIn)
                    ->whereBetween('created_at', $between);
            } else {
                $model = Db::table('wa_account_information_examine_approve')
                    ->select($fields)
                    ->where($condition)
                    ->whereNotIn('status', $whereNotIn);
            }
        }


        $count = $model->count();
        $list = $model
            ->orderBy('id', 'desc')
            ->offset($offset)
            ->limit($pageNum)
            ->get();


        if ($list) {
            foreach ($list as $k) {
                $acc_info_condition = [];
                $acc_info_condition [] = ['finance_no','=',$k->finance_no];
                $acc_info_data = WaAccountingInformation::find($acc_info_condition);
                if ($acc_info_data){
                    $acc_info_data = json_decode($acc_info_data);
                    $k->currency_name = IndexController::currencyNameCommon($acc_info_data->currency);
                    $k->payer_name = $acc_info_data->payer_name;
                    $k->receipt_number = $acc_info_data->receipt_number;
                }else{
                    $k->currency_name = '';
                    $k->payer_name = '';
                    $k->receipt_number = '';

                }


                //`status` int(11) DEFAULT NULL COMMENT '销售单审批状态 0 审批中 1 通过 2 驳回 3 撤回\r\n',
                $approve = WaAccountInformationExamineApproveFlow::all(
                    ['finance_no' => $k->finance_no, 'ai_no' => $k->ai_no]);
                $approve = json_decode($approve);
                if ($approve) {
                    foreach ($approve as $kpr) {
                        if ($kpr->admin_ids) {
                            if ($kpr->admin_ids){
                                $kpr->admin_ids = json_decode($kpr->admin_ids);
                            }
                            if ($kpr->status == 3) {
                                $approve_status = 3; // 已驳回
                                $approve_status_name = '已撤回';
                            } elseif ($kpr->status == 2) {
                                $approve_status = 2; // 已驳回
                                $approve_status_name = '已驳回';
                            } elseif ($kpr->status == 1) {
                                if (in_array($adminId->id, $kpr->admin_ids)) {
                                    $approve_status = 1; // 已审批
                                    $approve_status_name = '已审批';
                                } else {
                                    $approve_status = 998; // 审批中
                                    $approve_status_name = '审批中';
                                }

                            } elseif ($kpr->status == 0) {
                                if (in_array($adminId->id, $kpr->admin_ids)) {
                                    $approve_status = 0; // 待审批
                                    $approve_status_name = '待审批';
                                } else {
                                    $approve_status = 998; // 审批中
                                    $approve_status_name = '审批中';
                                }

                            } else {
                                $approve_status = 999; // 已驳回
                                $approve_status_name = '不在审批流中';
                            }
                        } else {
                            $approve_status = 10000; // 已驳回
                            $approve_status_name = '不在审批流中';
                        }


                    }
                } else {
                    $approve_status = 10001; // 审批状态
                    $approve_status_name = '没有审批记录';// 审批状态名称
                }

//                if ($approve) {
//                    foreach ($approve as $kpr) {
//                        $kpr->admin_ids = json_decode($kpr->admin_ids);
//                        if ($kpr->status == 3) {
//                            $approve_status = 3; // 已驳回
//                            $approve_status_name = '已撤回';
//                        } elseif ($kpr->status == 2) {
//                            $approve_status = 2; // 已驳回
//                            $approve_status_name = '已驳回';
//                        } elseif ($kpr->status == 1) {
//                            if (in_array($adminId->id, $kpr->admin_ids)){
//                                $approve_status = 1; // 已审批
//                                $approve_status_name = '已审批';
//                            }else{
//                                $approve_status = 998; // 审批中
//                                $approve_status_name = '审批中';
//                            }
//
//                        } elseif ($kpr->status == 0) {
//                            if (in_array($adminId->id, $kpr->admin_ids)){
//                                $approve_status = 0; // 待审批
//                                $approve_status_name = '待审批';
//                            }else{
//                                $approve_status = 998; // 审批中
//                                $approve_status_name = '审批中';
//                            }
//
//                        } else {
//                            $approve_status = 999; // 已驳回
//                            $approve_status_name = '不在审批流中';
//                        }
//                    }
//                } else {
//                    $approve_status = 10001; // 审批状态
//                    $approve_status_name = '没有审批记录';// 审批状态名称
//                }

                $k->approve_status = $approve_status; // 审批状态
                $k->approve_status_name = $approve_status_name;// 审批状态名称

                $k->approve_flow = json_decode($k->approve_flow);
                // 销售单审批状态 0 审批中 1 通过 2 驳回 3作废 4删除
                if ($k->status == 0) {
                    $k->status_name = '审批中';
                } elseif ($k->status == 1) {
                    $k->status_name = '审批通过';
                } elseif ($k->status == 2) {
                    $k->status_name = '审批驳回';
                } elseif ($k->status == 3) {
                    $k->status_name = '撤回审批';
                } elseif ($k->status == 4) {
                    $k->status_name = '已删除';
                } elseif ($k->status == 5) {
                    $k->status_name = '已撤回';
                } else {
                    $k->status_name = '';
                }
//                $orders = WaOrders::find(['order_sn' => $k->sales_order_sn]);
//                $orders = json_decode($orders);
//                if ($orders) {
//                    $k->user_name = $orders->user_name;
//                    $k->cnh = $orders->cnh;
//                    $k->currency = $orders->currency;
//
//
//                    $k->currency_name = \app\controller\wmapi\IndexController::currencyNameCommon($orders->currency);
//
//                } else {
//
//                    $k->user_name = '';
//                    $k->cnh = 0;
//                    $k->currency_name = '';
//                    $k->currency = '';
//
//                }
            }
        }
        return json_encode(['list' => $list, 'count' => $count]);


    }
    
    
    public static function waitApproveByAdminIdList($param,$adminId,$page, $pageNum, $purchasecontractsn, $fields = ['*'], $condition = []){
        $offset = ($page - 1) * $pageNum;
        // $purchasecontractsn 为空 就是没有当前登录用户的审核订单
        if (gettype($purchasecontractsn) == "object"){
            $purchasecontractsn = get_object_vars($purchasecontractsn); // 对象转数组函数
        }elseif (gettype($purchasecontractsn) == "array"){
            $purchasecontractsn = $purchasecontractsn;
        }
        if (!$purchasecontractsn){
            $count = 0;
            $list = [];
        }else{
            /**
             * 先获取审批中 待审批的 订单编号 和对应的审批id或编号
             * 审批流中的 部门id 必须是 当前人员的部门
             * 遍历审批流中的 部门admin_ids 中必须有当前人员 有他 但是并没有审批通过的状态就需要展示（因为轮到他时会有一条 0 待审批的状态 其它人会有 通过的状态 或者没有待审批记录）
             *
             */
            $wai_approve_sn = []; // 待当前人员审批的订单
            $where_approve = [];
            $where_approve [] = ['status', '=', 0]; // 先获取审批中 待审批的 订单编号 和对应的审批id或编号
            $approve = WaAccountInformationExamineApprove::all($where_approve);
            $approve = json_decode($approve);

            if ($approve) {
                foreach ($approve as $kap) {
                    $where_order = [];
                    $where_order [] = ['finance_no', '=', $kap->finance_no];
                    $order_data = WaAccountingInformation::find($where_order);
                    $order_data = json_decode($order_data);
                    if ($order_data) {
                        PublicCommentController::账单状态;
                        // 主订单是审批中的 才需要展示在待审批列表
                        if ($order_data->status == 1) {
                            // 现在开始查审批流
                            $where_approve_flow = [];
                            $where_approve_flow [] = ['finance_no', '=', $kap->finance_no]; // 先获取审批中 待审批的 订单编号 和对应的审批id或编号
                            $where_approve_flow [] = ['status', '=', 0]; // 先获取审批中 待审批的 订单编号 和对应的审批id或编号
                            $approve_flow = WaAccountInformationExamineApproveFlow::all($where_approve_flow);
                            $approve_flow = json_decode($approve_flow);
                            if ($approve_flow) {
                                foreach ($approve_flow as $kpl){
                                    if ($kpl->admin_ids) {
                                        $admin_ids = json_decode($kpl->admin_ids);
                                        if (in_array($adminId->id, $admin_ids)) {
                                            // 这个时候把审批订单编号扔出来 就是待当前人员待审核的数据
                                            array_push($wai_approve_sn, $kap->ai_no);
                                        }
                                    }
                                }

                            }

                        }
                    }
                }
            }
            
            


            $model = Db::table('wa_account_information_examine_approve')
                ->select($fields)
                ->where($condition)
                ->whereIn('ai_no',$wai_approve_sn);

            $count = $model->count();
            $list = $model
                ->orderBy('id', 'desc')
                ->offset($offset)
                ->limit($pageNum)
                ->get();
        }
        $condition [] = ['is_show','=',1];


        if ($list){
            foreach ($list as $k){

                $approve = WaAccountInformationExamineApproveFlow::all(
                    ['finance_no' => $k->finance_no, 'ai_no' => $k->ai_no]);
                $approve = json_decode($approve);
                if ($approve) {
                    foreach ($approve as $kpr) {
                        if ($kpr->admin_ids){
                            $kpr->admin_ids = json_decode($kpr->admin_ids);
                        }
                        if ($kpr->status == 3) {
                            $approve_status = 3; // 已驳回
                            $approve_status_name = '已撤回';
                        } elseif ($kpr->status == 2) {
                            $approve_status = 2; // 已驳回
                            $approve_status_name = '已驳回';
                        } elseif ($kpr->status == 1) {
                            if (in_array($adminId->id, $kpr->admin_ids)){
                                $approve_status = 1; // 已审批
                                $approve_status_name = '已审批';
                            }else{
                                $approve_status = 998; // 审批中
                                $approve_status_name = '审批中';
                            }

                        } elseif ($kpr->status == 0) {
                            if (in_array($adminId->id, $kpr->admin_ids)){
                                $approve_status = 0; // 待审批
                                $approve_status_name = '待审批';
                            }else{
                                $approve_status = 998; // 审批中
                                $approve_status_name = '审批中';
                            }

                        } else {
                            $approve_status = 999; // 已驳回
                            $approve_status_name = '不在审批流中';
                        }
                    }
                } else {
                    $approve_status = 10001; // 审批状态
                    $approve_status_name = '没有审批记录';// 审批状态名称
                }

                $k->approve_status = $approve_status; // 审批状态
                $k->approve_status_name = $approve_status_name;// 审批状态名称

                $k->approve_flow = json_decode($k->approve_flow);
                // 请款审批状态 0 审批中 1 通过 2 驳回 3作废 4删除
                if ($k->status == 0){
                    $k->status_name = '审批中';
                }elseif ($k->status == 1){
                    $k->status_name = '审批通过';
                }elseif ($k->status == 2){
                    $k->status_name = '审批驳回';
                }elseif ($k->status == 3){
                    $k->status_name = '撤回审批';
                }elseif ($k->status == 4) {
                    $k->status_name = '已删除';
                }elseif ($k->status == 5) {
                    $k->status_name = '作废';
                }else{
                    $k->status_name = '';
                }
//                $k->approve_flow = $k->approve_flow;
            }
        }
        return json_encode(['list' => $list, 'count' => $count]);


    }


    /**
     * 账单审批-状态修改
     * @param $data
     * @return int
     */
    public static function updated($condition,$data)
    {
        return Db::table('wa_account_information_examine_approve')->where($condition)->update($data);
    }

    /**
     * 账单审批-查询
     * 针对审批人员的状态 有已审批和轮到谁审批
     * @param $data
     * @return int
     */
    public static function find($adminId,$condition)
    {
        $res = Db::table('wa_account_information_examine_approve')
            ->where($condition)
            ->first();

        if ($res){
            $k = $res;

            $approve = WaAccountInformationExamineApproveFlow::all(
                ['finance_relevance_no' => $k->finance_relevance_no, 'ai_no' => $k->ai_no]);
            $approve = json_decode($approve);
            if ($approve) {
                foreach ($approve as $kpr) {
                        if ($kpr->admin_ids){
                            $kpr->admin_ids = json_decode($kpr->admin_ids);
                        }
                        if ($kpr->status == 3) {
                            $approve_status = 3; // 已驳回
                            $approve_status_name = '已撤回';
                        } elseif ($kpr->status == 2) {
                            $approve_status = 2; // 已驳回
                            $approve_status_name = '已驳回';
                        } elseif ($kpr->status == 1) {
                            if (in_array($adminId->id, $kpr->admin_ids)) {
                                $approve_status = 1; // 已审批
                                $approve_status_name = '已审批';
                            } else {
                                $approve_status = 998; // 审批中
                                $approve_status_name = '审批中';
                            }

                        } elseif ($kpr->status == 0) {
                            if (in_array($adminId->id, $kpr->admin_ids)) {
                                $approve_status = 0; // 待审批
                                $approve_status_name = '待审批';
                            } else {
                                $approve_status = 998; // 审批中
                                $approve_status_name = '审批中';
                            }

                        } else {
                            $approve_status = 999; // 已驳回
                            $approve_status_name = '不在审批流中';
                        }


                }
            } else {
                $approve_status = 10001; // 审批状态
                $approve_status_name = '没有审批记录';// 审批状态名称
            }

//                if ($approve) {
//                    foreach ($approve as $kpr) {
//                        $kpr->admin_ids = json_decode($kpr->admin_ids);
//                        if ($kpr->status == 3) {
//                            $approve_status = 3; // 已驳回
//                            $approve_status_name = '已撤回';
//                        } elseif ($kpr->status == 2) {
//                            $approve_status = 2; // 已驳回
//                            $approve_status_name = '已驳回';
//                        } elseif ($kpr->status == 1) {
//                            if (in_array($adminId->id, $kpr->admin_ids)){
//                                $approve_status = 1; // 已审批
//                                $approve_status_name = '已审批';
//                            }else{
//                                $approve_status = 998; // 审批中
//                                $approve_status_name = '审批中';
//                            }
//
//                        } elseif ($kpr->status == 0) {
//                            if (in_array($adminId->id, $kpr->admin_ids)){
//                                $approve_status = 0; // 待审批
//                                $approve_status_name = '待审批';
//                            }else{
//                                $approve_status = 998; // 审批中
//                                $approve_status_name = '审批中';
//                            }
//
//                        } else {
//                            $approve_status = 999; // 已驳回
//                            $approve_status_name = '不在审批流中';
//                        }
//                    }
//                } else {
//                    $approve_status = 10001; // 审批状态
//                    $approve_status_name = '没有审批记录';// 审批状态名称
//                }

            $k->approve_status = $approve_status; // 审批状态
            $k->approve_status_name = $approve_status_name;// 审批状态名称




            $res = $k;











//            $approve = WaAccountInformationExamineApproveFlow::all(
//                ['finance_relevance_no' => $res->finance_relevance_no,'ai_no' => $res->ai_no,'status' => 3]);
//            $approve = json_decode($approve);
//            if ($approve){
//                $approve_status = 3; // 已撤回
//                $approve_status_name = '已撤回';
//
//            }else{
//                $approve = WaAccountInformationExamineApproveFlow::all(
//                    ['finance_relevance_no' => $res->finance_relevance_no,'ai_no' => $res->ai_no,'department_id' => $adminId->department_id,'status' => 2]);
////                ['finance_no' => $res->finance_no,'ai_no' => $res->ai_no,'status' => 2]);
//                $approve = json_decode($approve);
//                if ($approve){
//                    $approve_status = 2; // 已驳回
//                    $approve_status_name = '已驳回';
//                }else{
//                    $approve = WaAccountInformationExamineApproveFlow::all(
//                        ['finance_relevance_no' => $res->finance_relevance_no,'ai_no' => $res->ai_no,'department_id' => $adminId->department_id,'status' => 1]);
////                    ['finance_no' => $res->finance_no,'ai_no' => $res->ai_no,'status' => 1]);
//                    $approve = json_decode($approve);
//                    if ($approve){
//                        $approve_status = 1; // 已审批
//                        $approve_status_name = '已审批';
//                    }else{
//                        $approve = WaAccountInformationExamineApproveFlow::all(
//                            ['finance_relevance_no' => $res->finance_relevance_no,'ai_no' => $res->ai_no,'department_id' => $adminId->department_id,'status' => 0]);
////                        ['finance_no' => $res->finance_no,'ai_no' => $res->ai_no,'status' => 0]);
//                        $approve = json_decode($approve);
//                        if ($approve){
//                            $approve_status = 0; // 待审批
//                            $approve_status_name = '待审批';
//                        }else{
//                            $approve_status = 999;// 待提交审批
//                            $approve_status_name = '待提交审批';
//                        }
//                    }
//                }
//
//            }
//            $res->approve_status = $approve_status; // 审批状态
//            $res->approve_status_name = $approve_status_name;// 审批状态名称
//        }else{
//            $res->approve_status = 999; // 待提交审批
//            $res->approve_status_name = '待提交审批';// 审批状态名称
        }
        return json_encode($res);
    }



    /**
     * 账单审批-查询
     * 针对审销售人员要观看的分配审批状态
     * @param $data
     * @return int
     */
    public static function findBySalesDetail($adminId,$condition)
    {
        $res = Db::table('wa_account_information_examine_approve')
            ->where($condition)
            ->first();

        if ($res){
            $k = $res;

            $approve = WaAccountInformationExamineApproveFlow::all(
                ['finance_relevance_no' => $k->finance_relevance_no, 'ai_no' => $k->ai_no]);
            $approve = json_decode($approve);
            if ($approve) {
                foreach ($approve as $kpr) {
                    if ($kpr->admin_ids){
                        $kpr->admin_ids = json_decode($kpr->admin_ids);
                    }
                    if ($kpr->status == 3) {
                        $approve_status = 3; // 已驳回
                        $approve_status_name = '已撤回';
                    } elseif ($kpr->status == 2) {
                        $approve_status = 2; // 已驳回
                        $approve_status_name = '已驳回';
                    } elseif ($kpr->status == 1) {
                            $approve_status = 1; // 已审批
                            $approve_status_name = '已审批';

                    } elseif ($kpr->status == 0) {
                            $approve_status = 0; // 待审批
                            $approve_status_name = '审批中';

                    } else {
                        $approve_status = 999; // 已驳回
                        $approve_status_name = '不在审批流中';
                    }


                }
            } else {
                $approve_status = 10001; // 审批状态
                $approve_status_name = '没有审批记录';// 审批状态名称
            }

//                if ($approve) {
//                    foreach ($approve as $kpr) {
//                        $kpr->admin_ids = json_decode($kpr->admin_ids);
//                        if ($kpr->status == 3) {
//                            $approve_status = 3; // 已驳回
//                            $approve_status_name = '已撤回';
//                        } elseif ($kpr->status == 2) {
//                            $approve_status = 2; // 已驳回
//                            $approve_status_name = '已驳回';
//                        } elseif ($kpr->status == 1) {
//                            if (in_array($adminId->id, $kpr->admin_ids)){
//                                $approve_status = 1; // 已审批
//                                $approve_status_name = '已审批';
//                            }else{
//                                $approve_status = 998; // 审批中
//                                $approve_status_name = '审批中';
//                            }
//
//                        } elseif ($kpr->status == 0) {
//                            if (in_array($adminId->id, $kpr->admin_ids)){
//                                $approve_status = 0; // 待审批
//                                $approve_status_name = '待审批';
//                            }else{
//                                $approve_status = 998; // 审批中
//                                $approve_status_name = '审批中';
//                            }
//
//                        } else {
//                            $approve_status = 999; // 已驳回
//                            $approve_status_name = '不在审批流中';
//                        }
//                    }
//                } else {
//                    $approve_status = 10001; // 审批状态
//                    $approve_status_name = '没有审批记录';// 审批状态名称
//                }

            $k->approve_status = $approve_status; // 审批状态
            $k->approve_status_name = $approve_status_name;// 审批状态名称




            $res = $k;











//            $approve = WaAccountInformationExamineApproveFlow::all(
//                ['finance_relevance_no' => $res->finance_relevance_no,'ai_no' => $res->ai_no,'status' => 3]);
//            $approve = json_decode($approve);
//            if ($approve){
//                $approve_status = 3; // 已撤回
//                $approve_status_name = '已撤回';
//
//            }else{
//                $approve = WaAccountInformationExamineApproveFlow::all(
//                    ['finance_relevance_no' => $res->finance_relevance_no,'ai_no' => $res->ai_no,'department_id' => $adminId->department_id,'status' => 2]);
////                ['finance_no' => $res->finance_no,'ai_no' => $res->ai_no,'status' => 2]);
//                $approve = json_decode($approve);
//                if ($approve){
//                    $approve_status = 2; // 已驳回
//                    $approve_status_name = '已驳回';
//                }else{
//                    $approve = WaAccountInformationExamineApproveFlow::all(
//                        ['finance_relevance_no' => $res->finance_relevance_no,'ai_no' => $res->ai_no,'department_id' => $adminId->department_id,'status' => 1]);
////                    ['finance_no' => $res->finance_no,'ai_no' => $res->ai_no,'status' => 1]);
//                    $approve = json_decode($approve);
//                    if ($approve){
//                        $approve_status = 1; // 已审批
//                        $approve_status_name = '已审批';
//                    }else{
//                        $approve = WaAccountInformationExamineApproveFlow::all(
//                            ['finance_relevance_no' => $res->finance_relevance_no,'ai_no' => $res->ai_no,'department_id' => $adminId->department_id,'status' => 0]);
////                        ['finance_no' => $res->finance_no,'ai_no' => $res->ai_no,'status' => 0]);
//                        $approve = json_decode($approve);
//                        if ($approve){
//                            $approve_status = 0; // 待审批
//                            $approve_status_name = '待审批';
//                        }else{
//                            $approve_status = 999;// 待提交审批
//                            $approve_status_name = '待提交审批';
//                        }
//                    }
//                }
//
//            }
//            $res->approve_status = $approve_status; // 审批状态
//            $res->approve_status_name = $approve_status_name;// 审批状态名称
//        }else{
//            $res->approve_status = 999; // 待提交审批
//            $res->approve_status_name = '待提交审批';// 审批状态名称
        }
        return json_encode($res);
    }


    public static function findApproveStatusByPrNo($condition)
    {
        $res = Db::table('wa_account_information_examine_approve')
            ->where($condition)
            ->first();

        return json_encode($res);
    }


    /**
     * 账单审批 -创建
     * @param $data
     * @return int
     */
    public static function create($data)
    {
        return Db::table('wa_account_information_examine_approve')->insertGetId($data);
    }


    /**
     * 账单审批 -删除
     * @param $data
     * @return int
     */
    public static function deleted($condition)
    {
        return Db::table('wa_account_information_examine_approve')->where($condition)->delete();
    }

    public static function all($condition)
    {
        $pageNum = 10;
        $condition [] = ['is_show','=',1];
        $list = Db::table('wa_account_information_examine_approve')
            ->select('*')
            ->where($condition)
            ->get();

        return json_encode($list);
    }

}